package com.yyn.vod.controller;

import com.aliyuncs.exceptions.ClientException;
import com.yyn.R;
import com.yyn.vod.service.VodService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/aliyunvod")
@CrossOrigin
public class VodController {
    @Autowired
    private VodService vodService;

    @PostMapping("upload")
    public R upload(MultipartFile file) {
        String videoId = vodService.uploadGetId(file);
        return R.success().data("videoId", videoId);
    }

    @DeleteMapping("removeVideo/{videoId}")
    public R removeVideo(@PathVariable String videoId) throws ClientException {
        boolean b = vodService.removeVideo(videoId);
        if (b) {
            return R.success().message("删除成功");
        }
        return R.error().message("删除失败");

    }
    @ApiOperation("获取视频凭证")
    @GetMapping("getVideoAuth/{id}")
    public R getVideoAuth(@PathVariable String id) throws ClientException {
        String videoAuth = vodService.getVideoAuth(id);
        return R.success().data("playAuth",videoAuth);
    }

}
